package com.guigu.dispatch.controller;


import com.guigu.dispatch.entity.CacheLine;
import com.guigu.dispatch.entity.CacheLineUse;
import com.guigu.dispatch.entity.OrderClassifyAttach;
import com.guigu.dispatch.entity.OrderClassifyOrder;
import com.guigu.dispatch.service.CacheLineService;
import com.guigu.dispatch.service.CacheLineUseService;
import com.guigu.dispatch.service.OrderClassifyOrderService;
import com.guigu.tms.result.R;
import com.guigu.tms.result.ResultCode;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 缓冲路线使用表 前端控制器
 * </p>
 *
 * @author TaoLong
 * @since 2021-11-18
 */
@RestController
@RequestMapping("/dispatch/cache-line-use")
public class CacheLineUseController {
    private CacheLineService cacheLineService;

    private CacheLineUseService cacheLineUseService;


    public CacheLineUseController(CacheLineService cacheLineService, CacheLineUseService cacheLineUseService) {
        this.cacheLineService = cacheLineService;
        this.cacheLineUseService = cacheLineUseService;
    }

    /**
     * 根据订单Id获取缓存线路表
     *
     * @param orderId
     * @return
     */
    @ApiOperation("根据订单Id获取缓存线路表")
    @GetMapping("/findCacheLineById/{orderId}")
    public CacheLineUse findCacheLineById(@PathVariable("orderId") String orderId) {
        CacheLineUse line = cacheLineService.findCacheLineById(orderId);
        if (ObjectUtils.isEmpty(line)) {
            return null;

        }
        return line;
    }

    /**
     * 根据订单Id获取车次车辆司机Id
     *
     * @param orderId
     * @return
     */
    @ApiOperation("根据订单Id获取车次车辆司机Id")
    @GetMapping("/findOrderClassifyAttachByOrderId/{orderId}")
    public OrderClassifyAttach findOrderClassifyAttachByOrderId(@PathVariable("orderId") String orderId) {
        OrderClassifyAttach orderClassifyAttach = cacheLineService.findOrderClassifyAttachByOrderId(orderId);
        if (ObjectUtils.isEmpty(orderClassifyAttach)) {
            return null;
        }
        return orderClassifyAttach;
    }

    /**
     * 根据订单分类Id获取线路Id
     *
     * @param orderClassifyId 订单分类id
     * @return
     */
    @ApiOperation("根据订单分类Id获取线路Id")
    @GetMapping("/getLineByOrderClassifyId/{orderClassifyId}")
    public R<String> getLineByOrderClassifyId(@PathVariable String orderClassifyId) {
        String s = cacheLineUseService.getLineByOrderClassifyId(orderClassifyId);
        if (StringUtils.isNotBlank(s)) {
            return new R<>(ResultCode.SUCCESS_CODE, s);
        }
        return new R<>(ResultCode.ERROR_CODE, null);
    }
}

